package cc.mrbird.febs.buss.controller;


import cc.mrbird.febs.buss.entity.*;
import cc.mrbird.febs.buss.service.*;
import cc.mrbird.febs.buss.util.ConfigResourceUtil;
import cc.mrbird.febs.buss.util.ExcelUtil;
import cc.mrbird.febs.buss.util.FileUtils;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.entity.FebsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  Controller
 *
 * @author Lujingyuan
 * @date 2020-02-27 18:08:45
 */
@Slf4j
@Validated
@Controller
@RequestMapping("web")
public class WebController extends BaseController {

    @Autowired
    private IItemService itemService;
    @Autowired
    private IMenuItemConnService menuItemConnService;
    @Autowired
    private IMenuItemPublicService menuItemPublicService;

    @Autowired
    private IMenuItemCompanyService menuItemCompanyService;

    @Autowired
    private IMenuItemPersonalService menuItemPersonalService;

    @Autowired
    private IMenuItemTextService menuItemTextService;
    @Autowired
    private IMenuItemFileService menuItemFileService;

    @ResponseBody
    @GetMapping("test")
    public FebsResponse test(){
        new ExcelUtil().impotExcel();
        System.out.println("-start--");
        System.out.println(ConfigResourceUtil.getConfigByName("abc"));
        System.out.println(FileUtils.getJarPath());
        System.out.println("-end--");
        return new FebsResponse().success().data(ConfigResourceUtil.getConfigByName("abc"));
    }

    @ResponseBody
    @GetMapping("getItemList")
    public FebsResponse getItemList(HttpServletRequest req){
        Map<String,Object> map=new HashMap<String,Object>();
        Enumeration paramNames = req.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();
            map.put(paramName,req.getParameter(paramName));
        }
        List<Item> list=itemService.selectByMap(map);
        req.setAttribute("itemList",list);
        return new FebsResponse().success().data(list);
    }

    @ResponseBody
    @GetMapping("getMenuContentList")
    public FebsResponse getMenuContentList(HttpServletRequest req){
        Map<String,Object> map=new HashMap<String,Object>();
        Enumeration paramNames = req.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();
            map.put(paramName,req.getParameter(paramName));
        }
        List<MenuItemPublic> alist=menuItemPublicService.selectConnByMap(map);
        List<MenuItemCompany> blist=menuItemCompanyService.selectConnByMap(map);
        List<MenuItemPersonal> clist=menuItemPersonalService.selectConnByMap(map);
        List<MenuItemText> textlist=menuItemTextService.selectConnByMap(map);
        List<MenuItemFile> filelist=menuItemFileService.selectConnByMap(map);
        return new FebsResponse().success().put("alist",alist).put("blist",blist).put("clist",clist).put("textlist",textlist).put("filelist",filelist);
    }

}
